# Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if(CMAKE_CROSSCOMPILING)
    add_library(iotsdk-serial-retarget OBJECT
        serial_retarget.c
        $<$<STREQUAL:${CMSIS_PACK_PLATFORM_DEVICE_NAME},SSE-300-MPS3>:platforms/mps3_uart.c>
        $<$<STREQUAL:${CMSIS_PACK_PLATFORM_DEVICE_NAME},SSE-310-MPS3_FVP>:platforms/mps3_uart.c>
        $<$<STREQUAL:${CMSIS_PACK_PLATFORM_DEVICE_NAME},SSE-310-MPS3_FPGA>:platforms/mps3_uart.c>
        $<$<STREQUAL:${CMAKE_C_COMPILER_ID},GNU>:toolchains/gcc_retarget.c>
        $<$<STREQUAL:${CMAKE_C_COMPILER_ID},ARMClang>:toolchains/armclang_retarget.c>
    )
    target_link_libraries(iotsdk-serial-retarget PRIVATE
        # Apply project options/warnings when the SDK is at the top level
        $<$<STREQUAL:${CMAKE_PROJECT_NAME},${PROJECT_NAME}>:project_options>
        $<$<STREQUAL:${CMAKE_PROJECT_NAME},${PROJECT_NAME}>:project_warnings>
    )

    add_library(iotsdk-alloc iotsdk_alloc.c)
    target_include_directories(iotsdk-alloc PUBLIC .)
    target_link_libraries(iotsdk-alloc PUBLIC
        # Apply project options/warnings when the SDK is at the top level
        $<$<STREQUAL:${CMAKE_PROJECT_NAME},${PROJECT_NAME}>:project_options>
        $<$<STREQUAL:${CMAKE_PROJECT_NAME},${PROJECT_NAME}>:project_warnings>
    )

endif()

if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
    add_subdirectory(mocks)
endif()
